package org.example.Queue;

import javax.swing.tree.TreeNode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;


//    static class Node{
//       int val;
//       Node next;
//       public Node(int data){
//           this.val = data;
//       }
//    }
//    public static Node head;
//    public static Node tail;
//    public static void disPlay(){
//        Node cur = head;
//        while (cur!=null){
//            System.out.print(cur.val +" ");
//            cur = cur.next;
//        }
//        System.out.println();
//
//    }
//    public static void push(int data){
//        Node node = new Node(data);
//        if(head==null){
//            head = tail = node;
//        }
//        tail.next = node;
//        tail = tail.next;
//    }
//    public static void remove(){
//        if(head ==null&&tail==null){
//            System.out.println("当前元素已为空，禁止删除");
//            return;
//        }
//        if(head.next==null){
//            head = tail = null;
//        }else{
//            head = head.next;
//        }
//
//    }
public class Main {
    public class TreeNode{
        char val;
        TreeNode left;
        TreeNode right;
        TreeNode(char val){
            this.val = val;
        }
    }
    public  int i = 0;
    public static void main(String[] args) {
        Main main = new Main();
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入二叉树序列");
        String res = sc.nextLine();
        TreeNode root = main.createTree(res);
        inOrder(root);
    }

    private static void preOrder(TreeNode root) {
       if(root==null)
            return ;
        System.out.println(root.val);
        inOrder(root.left);
        inOrder(root.right);
    }
    private static void inOrder(TreeNode root) {
        if(root==null)
            return ;
        inOrder(root.left);
        System.out.println(root.val);
        inOrder(root.right);
    }
    private static void postOrder(TreeNode root) {
        if(root==null)
            return ;
        inOrder(root.left);
        inOrder(root.right);
        System.out.println(root.val);
    }
    private  TreeNode createTree(String res) {
        TreeNode root = null;
        if(res.charAt(i)!='#'){
            char ch = res.charAt(i);
            root = new TreeNode(ch);
            i++;
            root.left = createTree(res);
            root.right = createTree(res);
        }else{
            i++;
        }
        return root;
    }

    public static void main3(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.remove(0);
        list.remove(0);

        System.out.println(list.indexOf(3));
    }

    public static void main2(String[] args) {
        String s1 ="abcdefghijklmnopqrstuvwxyz";
        String s2 ="ngzqtcobmuhelkpdawxfyivrsj";
        HashMap<Character,Character> hash = new HashMap<>();
        int m = 0,n=0;
        while (m<s1.length()){
            hash.put(s1.charAt(m),s2.charAt(n));
            m++;
            n++;
        }
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入字符串");
        String src = sc.nextLine();
        String dest="";
        for (int i = 0; i < src.length(); i++) {
            String s = hash.get(src.charAt(i))+"";
            dest+=s;
        }
        System.out.println("解密后的字符串"+dest);
    }
    public static void main1(String[] args) {
        push(1);
        push(2);
        push(3);
        push(4);
        disPlay();
        remove();
        remove();
        disPlay();
    }
}